package io.github.wx.web;

import com.jfinal.aop.Before;
import com.jfinal.aop.Duang;
import io.github.wx.common.controller.BaseController;
import io.github.wx.common.easyui.DataGrid;
import io.github.wx.common.easyui.TreeNode;
import io.github.wx.common.redis.RedisCacheInterceptor;
import io.github.wx.dao.model.SysRole;
import io.github.wx.service.MenuService;
import io.github.wx.service.RoleService;

import java.util.List;

/**
 * Created by jie on 2017/4/7.
 * 后台基本管理
 * /admin
 */
public class SysRoleMenuController extends BaseController {
    static final RoleService roleService = Duang.duang(RoleService.class);
    static final MenuService menuService = Duang.duang(MenuService.class);

    /**
     * 角色管理
     */
    public void roleManage() {
        render("role/roleManage.html");
    }

    /**
     * 获取角色列表
     */
    public void roleList() {
        DataGrid<SysRole> dataGrid = roleService.getRolePage(getParaToInt("page"), getParaToInt("rows"));
        renderJson(dataGrid);
    }

    /**
     * 获取角色id-value
     */
    @Before(RedisCacheInterceptor.class)
    public void roleCombo() {
        List<SysRole> roleList = roleService.roleCombo();
        renderJson(roleList);
    }

    /**
     * 菜单管理
     */
    public void menuManage() {
        render("menu/menuManage.html");
    }

    /**
     * 获取菜单列表
     */
    public void menuList() {
        List<TreeNode> treeNodeList = menuService.selectAll();
        renderJson(treeNodeList);
    }
}
